package gsm.cable.client.view;

import gsm.cable.client.DefaultConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;

public class ViewWidget extends Composite {
	private static ViewWidgetUiBinder uiBinder = GWT.create(ViewWidgetUiBinder.class);
	@UiField
	HTML emailIdLabel;

	@UiField
	Image headerLogo;

	@UiField
	HTML organizationTitle;

	@UiField
	HTML organizationSlogan;

	@UiField
	ScrollPanel bodyPanel;

	@UiField
	HTML copyrightMessage;

	@UiField
	Anchor signInLink;

	interface ViewWidgetUiBinder extends UiBinder<Widget, ViewWidget> {
	}

	public ViewWidget() {
		initWidget(uiBinder.createAndBindUi(this));
//		setEmailIdLabel("shaktijaiswal13@gmail.com");
		setHeaderLogo(DefaultConstants.HEADER_LOGO_URL);
		setOrganizationTitle(DefaultConstants.ORGANIZATION_TITLE);
		setOrganizationSlogan(DefaultConstants.ORGANIZATION_SLOGAN);
		setSignInUrl("/login.html");
		BodyWidget bodyWidget = new BodyWidget();
		setCopyrightMessage(DefaultConstants.COPY_RIGHT_MESSAGE);
		setBody(bodyWidget);
		Window.addResizeHandler(new ResizeHandler() {

			@Override
			public void onResize(ResizeEvent event) {
				setBodyPanelSize();

			}
		});
	}

	public void setEmailIdLabel(String emailId) {
		this.emailIdLabel.setText(emailId);
	}

	public void setCopyrightMessage(String copyrightMessage) {
		this.copyrightMessage.setHTML(copyrightMessage);
	}

	public void setBody(Widget body) {
		setBodyPanelSize();
		this.bodyPanel.add(body);
	}

	private void setBodyPanelSize() {
		int height = Window.getClientHeight() - 124;
		int width = Window.getClientWidth() - 10;
		this.bodyPanel.setSize(width + "px", height + "px");
	}

	public void setHeaderLogo(String headerLogoUrl) {
		this.headerLogo.setUrl(headerLogoUrl);
	}

	public void setOrganizationTitle(String organizationTitle) {
		this.organizationTitle.setHTML(organizationTitle);
	}

	public void setOrganizationSlogan(String organizationSlogan) {
		this.organizationSlogan.setHTML(organizationSlogan);
	}

	public void setSignInUrl(String signInUrl) {
		this.signInLink.setHref(signInUrl);
	}
}
